<template>
	<view class="container">

		<view class="use_item">
			<view class="title">
				学校名称
			</view>
			<input placeholder="请选择学校名称" v-model="form.school" placeholder-style="color:#CCCCCC;font-size:32rpx" />
			<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
		</view>
		<view class="use_item">
			<view class="title">
				入学时间
			</view>
			<picker mode="date" :value="sdate" :start="startDate" :end="endDate" @change="sdateChange">
				<view>{{sdate}}</view>
			</picker>
			<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
		</view>

		
		<view class="use_item">
			<view class="title">
				毕业时间
			</view>
			<picker mode="date" :value="edate" :start="startDate" :end="endDate" @change="edateChange">
				<view>{{edate}}</view>
			</picker>
			<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
		</view>
		<view class="use_item">
			<view class="title">
				所学专业
			</view>
			<ld-select :list="options"
			        list-key="label" value-key="value"
			        placeholder="请选择所学专业"
			        v-model="form.major"
					selectBgColor="#ccc"
			        @change="selectChange">
			</ld-select>
			<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
		</view>
		<HandleBtn btnName="保存" @click.native="addeducation()"   class="confirm_btn"></HandleBtn>
	</view>
</template>

<script>
	import HandleBtn from "../../components/handleBtn.vue"
	export default {
		components: {
			HandleBtn
		},
		data() {
			return {
				options:[{
				      value: '哲学',
				      label: '哲学'
				    }, {
				      value: '历史学',
				      label: '历史学'
				    }, {
				      value: '文学',
				      label: '文学'
				    }, {
				      value: '教育学',
				      label: '教育学'
				    }, {
				      value: '经济学',
				      label: '经济学'
				    },{
				      value: '艺术学',
				      label: '艺术学'
				    },{
				      value: '法学',
				      label: '法学'
				    },{
				      value: '理学',
				      label: '理学'
				    }],
				form:{
					school:"",
					beginTime:"",
					endTime:"",
					major :"",
					remark:""
				},	
				sdate: '请选择开始时间',
				edate:'请选择结束时间'
					
				}
		},
		methods: {
			selectChange(value){
				this.form.major = value
			},
			addeducation(){
				this.$utils.requert({url:'educationAdd',data:this.form,type:'post'}).then(res=>{
						if(res.code === 1 ){
							this.$utils.showLayer(res.message)
							uni.navigateBack({
								delta:1
							})
						}else{    
							this.$utils.showLayer(res.message)
						}
					})
			},
			// 选择日期
				edateChange(e) {
					this.edate = e.target.value
					this.form.endTime = e.target.value
				},
				sdateChange(e) {
					this.sdate = e.target.value
					this.form.beginTime = e.target.value
				},
				// 获取年月日信息
				getDate(type) {
					const date = new Date();
					let year = date.getFullYear();
					let month = date.getMonth() + 1;
					let day = date.getDate();
				
					if (type === 'start') {
						year = year - 60;
					} else if (type === 'end') {
						year = year + 2;
					}
					month = month > 9 ? month : '0' + month;;
					day = day > 9 ? day : '0' + day;
					return `${year}-${month}-${day}`;
				}
			},
			computed: {
					startDate() {
						return this.getDate('start');
					},
					endDate() {
						return this.getDate('end');
					}
			},
		}
</script>
<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #fff;
	}
</style>

<style scoped>
	.container {
		width: 100%;
		height: 100%;
	}

	.use_item {
		padding: 38rpx 0;
		margin:0 24rpx;
		box-sizing: border-box;
		border-bottom: 1rpx solid #f6f6f6;
		display: flex;
		align-items: center;
	}
	.use_item .title {
		font-size: 32rpx;
		color: #868686;
		width: 45%;
	}

	.use_item input {
		font-size: 32rpx;
		text-align: left;
	}
	.use_item picker {
		font-size: 32rpx;
	}
	.use_item image{
		width: 14rpx;
		height: 24rpx;
		margin-left: auto;
	}
	.tip{
		font-size: 32rpx;
		color: #333333;
		margin-bottom: 34rpx;
	}
	textarea{
		background-color: #f5f4f6;
		font-size: 28rpx;
		width: 100%;
		border-radius: 7rpx;
		padding:32rpx 24rpx;
		box-sizing: border-box;
	}
	.car_require {
		padding:50rpx 24rpx;
		box-sizing: border-box;
	}
	.car_image{
		padding:0 24rpx 50rpx;
		box-sizing: border-box;
	}
	.car_image .tip{
		display: flex;
	}
	.car_image .tip .no_require{
		font-size: 28rpx;
		color: #BBBBBB;
	}
	.car_image .package_img{
		width:200rpx;
		height: 200rpx;
		background-color: #f5f4f6;
		text-align: center;
	}
	.car_image .package_img image{
		width:79rpx;
		height: 76rpx;
		margin-top: 62rpx

	}
	.confirm_btn{
		margin-top: 166rpx;
		margin-bottom: 70rpx;
	}
	.uni-input-placeholder{
		text-align: left;
	}
</style>
